{$CLEO .cs}
{$USE CLEO+}
{$USE newOpcodes}
{$USE ini}

0000: NOP

script_name "Ratqa"

// By ArtemQa146

if
    0E2D: is_game_first_start
then
    0F00: load_special_model_dff "ModelsQa\ratqa" txd "ModelsQa\ratqa" store_to 0@
    0AF1: write_int 0@ to_ini_file "cleo\Ratqa.ini" section "Models" key "Ratqa"
    0F00: load_special_model_dff "ModelsQa\ratqa2" txd "ModelsQa\ratqa" store_to 0@
    0AF1: write_int 0@ to_ini_file "cleo\Ratqa.ini" section "Models" key "Ratqa2"
end

const
    obj_1 = 31@
    render_1 = 30@
    render_2 = 29@
    distance = 28@
    spawn = 27@
    find = 26@
    obj_find = 25@
    find_kill = 24@
    stopped = 23@
    rANDOM_TIME = 22@
    render_model_1 = 21@
    render_model_2 = 20@
    size_ini = 19@
end

0AF0: render_model_1 = read_int_from_ini_file "cleo\Ratqa.ini" section "Models" key "Ratqa"
0AF0: render_model_2 = read_int_from_ini_file "cleo\Ratqa.ini" section "Models" key "Ratqa2"
0AF2: size_ini = read_float_from_ini_file "cleo\Ratqa.ini" section "Settings" key "Size"


while true
wait 1000
    if and
        $ACTIVE_INTERIOR == 0
        player.Defined(0)
    then
    
        0AAA: 1@ = get_script_struct_named "ratqa2"
        if
            1@ == 0
        then
        
            spawn = false
            find = 0
            while get_any_object_no_save_recursive find progress_to find object_to obj_find

                if or
                    09CC:   object obj_find model_is 1227
                    09CC:   object obj_find model_is 1345
                    09CC:   object obj_find model_is 1372
                    09CC:   object obj_find model_is 1344
                    09CC:   object obj_find model_is 1439
                then
                    if and
                        0EE6: locate_char_distance_to_object $player_actor object obj_find radius 40.0
                        not locate_char_distance_to_object $player_actor object obj_find radius 20.0
                    then
                        0400: store_coords_to 1@ 2@ 3@ from_object obj_find with_offset 0.0 0.0 2.0
                        spawn = true
                        break
                    end
        
                end
            end

    
            if
                spawn == true
            then

                0E40: get_current_hour 5@
                if and
                    5@ >= 7
                    5@ <= 21
                then
                    0209: 4@ = random_int_in_ranges 0 3
                else
                    0209: 4@ = random_int_in_ranges 1 5
                end
                
                02C0: store_to 6@ 7@ 8@ ped_path_coords_closest_to 1@ 2@ 3@
                0509: 9@ = distance_between_XY 6@ 7@ and_XY 1@ 2@

                if
                    9@ > 10.0
                then

                    for 5@ = 0 to 4@ step 1
                    0A92: stream_custom_script "ratqa2.qa" 1@ 2@ 3@ render_model_1 render_model_2 size_ini
                    end
                else
                    0E40: get_current_hour 5@
                    if and
                        5@ >= 7
                        5@ <= 21
                    then
                        if
                            0E4D: random_percent 25
                        then
                            0A92: stream_custom_script "ratqa2.qa" 1@ 2@ 3@ render_model_1 render_model_2 size_ini
                        else
                            wait 5000
                        end
                    else
                        0209: 4@ = random_int_in_ranges 0 2
                        for 5@ = 0 to 4@ step 1
                        0A92: stream_custom_script "ratqa2.qa" 1@ 2@ 3@ render_model_1 render_model_2 size_ini
                        end
                    end
                end
            end
        end
    end
end